//app.js
App({
  data:{
    url:'http://h05.mryangping.com',
    uniacid:9,
    m:'aa_spread'
  },
  onLaunch: function () {
    wx.getSystemInfo({
      success: function (res) {
        wx.setStorageSync("systemInfo", res)
      },
    })
  },
  userLogin: function () {
    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        wx.getUserInfo({
          lang:'zh_CN',
          success: user => {
            console.log(user)
            wx.request({
              url: this.publicUrl('login'),
              data: {
                code: res.code,
                nickname: user.userInfo.nickName,
                headimgurl: user.userInfo.avatarUrl,
                sex: user.userInfo.gender,
                city: user.userInfo.city,
                country: user.userInfo.country,
                province: user.userInfo.province
              },
              success: function (r) {
                console.log(r)
                wx.setStorageSync("openId", r.data.data.openid);
              }
            })
          }
        })
      }
    })
  },
  publicUrl:function(d){
    return this.data.url+"/app/index.php?i="+this.data.uniacid+"&c=entry&a=wxapp&do=" + d + "&m="+this.data.m
  },
  globalData: {
    userInfo: null,
    // publicUrl: "http://h05.mryangping.com/app/index.php?i=9&c=entry&a=wxapp&do=login&m=aa_spread"
  }
})